import express from "express"
import db from "./db.js"
import model from "./model.js"

const app = express()

const port = process.env.port || 3000

console.log(
    process.env.NODE_ENV
)

let Actcode = model.Actcode
console.log(Actcode)
let Code = model.Code

db.sync()

const actco = await Actcode.create({ 
    status:0,
    code:'UYSHJE7675SAD',
    codeid:"8237487-3232-3232-3342-8839242" 
})

app.get('/',(req,res) => {
    res.type('text/plain')
    res.send('Hello world！')
})

//定制404页
app.use((req,res) => {
    res.type('text/plain')
    res.status(404)
    res.send('404 - Not Found')
})

app.use((err,req,res,next) => {
    console.error(err.message)
    res.type('text/plain')
    res.status(500)
    res.send('500 - Server Error')
})

app.listen(port,() => {
    console.log(`Express started on http://localhost:${port};`+
        `press Ctrl-C to terminate.`
    )
})